package site.yunnong.atvris.admin.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import site.yunnong.atvris.dao.admin.service.SysUserManageService;
import site.yunnong.atvris.dao.admin.vo.UserVo;
import site.yunnong.atvris.dao.common.api.CommonPage;
import site.yunnong.atvris.dao.common.api.CommonResult;
import site.yunnong.atvris.dao.common.param.UserQueryParam;
import site.yunnong.atvris.dao.common.util.LocalAssert;

import java.util.List;

/**
 * @author JinghaoZhang
 * @date 2021年-06月-21日
 */
@Slf4j
@Api(tags = "个人用户管理")
@RestController
@RequestMapping("/sys/user")
public class SysUserManageController {

    @Autowired
    private SysUserManageService sysUserManageService;

    @ApiOperation(value = "禁用/启用账户")
    @PatchMapping("/permission")
    public CommonResult changePermission(@RequestParam("id") Long id, @RequestParam("status") Integer status) {
        int count = sysUserManageService.changePermission(id, status);
        LocalAssert.notZero(count, "操作失败");
        return CommonResult.success();
    }

    @ApiOperation(value = "根据条件获取用户列表")
    @PostMapping("/list")
    public CommonResult query(@RequestBody UserQueryParam param,
                              @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
                              @RequestParam(value = "pageSize", required = false, defaultValue = "20")Integer pageSize) {
        List<UserVo> umsUserList = sysUserManageService.query(param, pageNum, pageSize);
        CommonPage<UserVo> page = CommonPage.selfPage(pageNum, pageSize, umsUserList, 20L);
        return CommonResult.success(page);
    }


}
